﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.WebCommon.Common;
using SMTC.BO.Role;
using SMTC.Model.TestCore;
using SMTC.Model.Model;
using SMTC.BO.Plan;

public partial class RoleManagement_ViewMemberInRole :BasePage
{
    RoleQueryService query = new RoleQueryService();
    RoleProcessService proc = new RoleProcessService();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
           
            if ( Request["action"].ToString() == "select" && Request["RoleID"] != null)
            {
                ViewState["RoleID"] = Request["RoleID"].ToString();
                hidRoleID.Value = ViewState["RoleID"].ToString();
                    try
                    {
                        List<EmpInfo> list = query.GetMemberInRoleList(ViewState["RoleID"].ToString()); ;

                        foreach (EmpInfo item in list)
                        {
                            if (item != null)
                            {
                                ListItem li = new ListItem(item.UserName, item.UserID);
                                this.lbAddedMember.Items.Add(li);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowMessage(Resources.Resource.ErrorForGetMounterList);//"取得贴片机列表失败！请联系管理员"
                        return;
                    }
                    lbAddedMember.DataBind();
         
            }
        }
    }
    protected void btnInsert_OnClick(object sender, EventArgs e)
    {
        List<SMT_MemberInRole_Model> memberlist=new List<SMT_MemberInRole_Model>();
        foreach (ListItem item in lbAddedMember.Items)
        {
           
            SMT_MemberInRole_Model member_model=new SMT_MemberInRole_Model();
            member_model.RoleID = ViewState["RoleID"].ToString();
            member_model.MemberID = item.Value;
             memberlist.Add(member_model); 

        }
        if (proc.INSERT_MEMBER_IN_ROLE(memberlist,ViewState["RoleID"].ToString()))
        {
            this.ShowMessage("Success!");//"生产线信息添加成功！"

        }
        else
        {
         //   this.ShowMessage(Resources.Resource.LineInfoAddFailed);//"生产线信息添加失败！请稍后重试！"
            this.ShowMessage("Failed");
        }
        this.btnInsert.Visible = false;

    }
    protected void btnAddMember_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.HidAddedMember.Value) && this.HidAddedMember.Value.ToLower() != "undefined")
        {
            string[] pu = this.HidAddedMember.Value.Split(';');

            if (pu.Length == 0) return;
            for (int i = 0; i < pu.Length; i++)
            {
                bool flag = true;

                for (int j = 0; j < lbAddedMember.Items.Count; j++)
                {

                    if (lbAddedMember.Items[j].Value == pu[i].Split(',')[0].ToString())
                    {
                        flag = false;

                    }

                }
                if (flag)
                {
                    lbAddedMember.Items.Add(new ListItem(pu[i].Split(',')[1].ToString(), pu[i].Split(',')[0].ToString()));

                }

            }
        }

    }
    protected void btnRemovePU_Click(object sender, EventArgs e)
    {

        while (lbAddedMember.SelectedIndex != -1)
        {
            lbAddedMember.Items.Remove(this.lbAddedMember.SelectedItem);
        }
        if (lbAddedMember.Items.Count == 0)
        {
            this.HidAddedMember.Value = "";
        }

    }
}